<template>
  <div class="article-card" :class="{ 'reverse': isReverse }" @click="handleClick(article)">
    <div class="article-image">
      <img :src="article.coverImage ? getStaticUrl(article.coverImage) : 'https://via.placeholder.com/340x200'" :alt="article.title">
      <div class="article-status" v-if="article.status === 0">
        <span class="status-icon draft">
          <i class="icon-status"></i>
          草稿
        </span>
      </div>
    </div>
    <div class="article-content">
      <h2 class="article-title">{{ article.title }}</h2>
      <div class="article-meta">
        <span class="article-date"><CalendarOutlined/> {{ formatDate(article.createTime) }}</span>
        <span class="article-views"><EyeOutlined/> 阅读：{{ article.viewCount || 0 }}</span>
      </div>
      <p class="article-summary">{{ article.summary }}</p>
      <div class="article-footer">
        <span class="read-more-text">阅读全文</span>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { defineProps, defineEmits } from 'vue';
import { CalendarOutlined, EyeOutlined, AppstoreOutlined } from '@ant-design/icons-vue';
import router from '@/router';
import { getStaticUrl } from '@/utils/url';
const props = defineProps({
  article: {
    type: Object,
    required: true
  },
  isReverse: {
    type: Boolean,
    default: false
  }
});

defineEmits(['click']);
const handleClick = (article) => {
  console.log(article);
  router.push({
    path: '/article/' + article.id
  });
};
const formatDate = (dateStr) => {
  if (!dateStr) return '';
  const date = new Date(dateStr);
  return date.toLocaleDateString('zh-CN', { 
    year: 'numeric', 
    month: 'long', 
    day: 'numeric' 
  });
};
</script>

<style scoped>
.article-card {
  display: flex;
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  margin-bottom: 30px;
  transition: transform 0.3s, box-shadow 0.3s;
  cursor: pointer;
}

.article-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.reverse {
  flex-direction: row-reverse;
}

.article-image {
  flex: 0 0 340px;
  width: 340px;
  height: 200px;
  overflow: hidden;
  position: relative;
}

.article-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s;
}

.article-card:hover .article-image img {
  transform: scale(1.05);
}

.article-status {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
}

.status-icon {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  color: white;
}

.status-icon.draft {
  background-color: #faad14;
}

.icon-status {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  background-color: currentColor;
}

.article-content {
  flex: 1;
  padding: 25px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-height: 200px;
}

.article-title {
  margin: 0 0 10px;
  font-size: 1.5rem;
  color: #333;
  white-space: normal;
  word-break: break-word;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.article-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: #888;
  margin-bottom: 15px;
  flex-wrap: wrap;
}

.article-meta span {
  display: flex;
  align-items: center;
  margin-right: 10px;
}

.icon-calendar::before {
  content: '📅';
  margin-right: 5px;
}

.icon-eye::before {
  content: '👁️';
  margin-right: 5px;
}

.article-summary {
  color: #666;
  line-height: 1.6;
  margin-bottom: 20px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.article-footer {
  margin-top: auto;
}

.read-more-text {
  display: inline-block;
  color: #42b983;
  font-weight: 500;
  position: relative;
}

.read-more-text::after {
  content: '→';
  margin-left: 5px;
  transition: transform 0.3s;
}

.article-card:hover .read-more-text::after {
  transform: translateX(3px);
}

.reverse .article-status {
  right: auto;
  left: 10px;
}

@media (max-width: 768px) {
  .article-card, .article-card.reverse {
    flex-direction: column;
  }
  
  .article-image {
    width: 100%;
    flex: none;
    height: 200px;
  }
  
  .article-status {
    right: 10px;
    left: auto;
  }
}
</style> 